﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		TrackbackMessage.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 // 
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion

using System;
using System.Globalization;
using Dexter.Domain.Model;

namespace Dexter.Web.Utils {

	#region Usings

	#endregion

	public class TrackBackMessage {
		/// <summary>
		/// 	Initializes a new instance of the <see cref = "TrackBackMessage" /> class.
		/// </summary>
		/// <param name = "item">The item.</param>
		/// <param name = "urlToNotifyTrackback">The URL to notify trackback.</param>
		/// <param name = "itemUrl"></param>
		/// <exception cref = "ArgumentNullException"><c>item</c> is null.</exception>
		public TrackBackMessage ( Item item , Uri urlToNotifyTrackback , Uri itemUrl ) {
			if ( item == null ) {
				throw new ArgumentNullException ( "item" );
			}

			Title = item.Title;
			PostUrl = itemUrl;
			Excerpt = item.Title;
			UrlToNotifyTrackback = urlToNotifyTrackback;
		}

		/// <summary>
		/// 	Gets or sets the title.
		/// </summary>
		/// <value>The title.</value>
		public string Title { get; set; }

		/// <summary>
		/// 	Gets or sets the post URL.
		/// </summary>
		/// <value>The post URL.</value>
		public Uri PostUrl { get; set; }

		/// <summary>
		/// 	Gets or sets the excerpt.
		/// </summary>
		/// <value>The excerpt.</value>
		public string Excerpt { get; set; }

		/// <summary>
		/// 	Gets or sets the name of the blog.
		/// </summary>
		/// <value>The name of the blog.</value>
		public string BlogName { get; set; }

		/// <summary>
		/// 	Gets or sets the URL to notify trackback.
		/// </summary>
		/// <value>The URL to notify trackback.</value>
		public Uri UrlToNotifyTrackback { get; set; }

		/// <summary>
		/// 	Returns a <see cref = "T:System.String"></see> that represents the current <see cref = "T:System.Object"></see>.
		/// </summary>
		/// <returns>
		/// 	A <see cref = "T:System.String"></see> that represents the current <see cref = "T:System.Object"></see>.
		/// </returns>
		public override string ToString ( ) {
			if ( string.IsNullOrEmpty ( UrlToNotifyTrackback.Query ) ) {
				return String.Format ( CultureInfo.InvariantCulture , "?title={0}&url={1}&excerpt={2}&blog_name={3}" , Title , PostUrl , Excerpt , BlogName );
			}

			return String.Format ( CultureInfo.InvariantCulture , "&title={0}&url={1}&excerpt={2}&blog_name={3}" , Title , PostUrl , Excerpt , BlogName );
		}
	}
}
